Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: all in one migration command #3250

Merged
merged 25 commits into from
Oct 10, 2024
Merged

feat: all in one migration command #3250

merged 25 commits into from
Oct 10, 2024

Conversation

dickermoshe
Copy link
Collaborator

@dickermoshe dickermoshe commented Sep 30, 2024

Generates Dumped Schema, Tests and Steps with a single command.
Uses build.yaml config to define database and file paths.

Fixes: #3216

This basically wraps generate,dump and steps`.
A small refactor is needed to make the code in each of those commands reusable by this new command.

@github-actions github-actions bot temporarily deployed to commit September 30, 2024 12:22 Inactive
Copy link

github-actions bot commented Sep 30, 2024

🚀 Deployed on https://deploy-preview-3250--moor.netlify.app

@github-actions github-actions bot temporarily deployed to pull request September 30, 2024 12:25 Inactive
Copy link
Owner

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was worried about supporting multiple databases, but splitting generated migration assets into different directories is a clever solution.
The implementation looks good to me, some things I'm wondering from a DX perspective:

  1. Most users will have exactly one database - I think we should make that case a little easier by also allowing a simple String (as a file path) in the databases option (or perhaps with a separate database key).
  2. Maybe we could use the entries of that map to not only configure the name of the database (which doesn't appear to be considered for file paths) but also the location under test/ where the default test should be added to?
  3. I kind of view this as a "make the first migration tooling setup easier" command. In particular, I imagine that users will want to use the output of writeGeneratedTest() as a starting point to add own migration tests too. So maybe we shouldn't overwrite the file every time and instead only write it if it doesn't exist?

@dickermoshe
Copy link
Collaborator Author

1 will require fighting with freezed. Not sure how to do that? sealed unions?
2 & 3 are already in the works.

@simolus3
Copy link
Owner

1 will require fighting with freezed

We're using json serializable. I think you can keep the field for this and then use @JsonKey with a fromJson annotation to keep maps unchanged and map and strings to a single-element map. Don't spend too much time on this, I can figure it out if needed.

@dickermoshe
Copy link
Collaborator Author

We must resolve #3219 (comment)

@dickermoshe dickermoshe force-pushed the drift_migrator_tool branch 2 times, most recently from 65ef5b3 to 3a37d49 Compare October 6, 2024 00:37
@github-actions github-actions bot temporarily deployed to commit October 6, 2024 02:20 Inactive
@github-actions github-actions bot temporarily deployed to pull request October 6, 2024 02:20 Inactive
@dickermoshe
Copy link
Collaborator Author

@simolus3 How do you suppose I write tests for all this.

Most of this functionality is copied from generate, steps and dump.
The only additional feature is the data validation, which is just a scaffold users fill with before and after data.

@github-actions github-actions bot temporarily deployed to pull request October 6, 2024 02:28 Inactive
@github-actions github-actions bot temporarily deployed to commit October 6, 2024 02:28 Inactive
@github-actions github-actions bot temporarily deployed to commit October 6, 2024 02:41 Inactive
@github-actions github-actions bot temporarily deployed to pull request October 6, 2024 02:41 Inactive
@dickermoshe dickermoshe marked this pull request as ready for review October 6, 2024 04:50
@github-actions github-actions bot temporarily deployed to pull request October 6, 2024 04:55 Inactive
@github-actions github-actions bot temporarily deployed to commit October 6, 2024 04:55 Inactive
@dickermoshe
Copy link
Collaborator Author

dickermoshe commented Oct 6, 2024

@simolus3
Read for review. Tests are all written, lmk if you think I've missed something.

I did not implement point 1 myself. Left for you to implement - it's likely quicker for you given your familiarity with json_serializable.

Regarding point 3, we could put a function in the generated v_toV_.dart files which are not overwritten.
What do you think this function would look like and when should it be ran?

Overall, I this is coming together much quicker than I would like.
This is a tool I would personally find very useful, however it's possible that I overlooked something.


Please try this out yourself in practice and Lmk what the user experience is like.
It's hard to put myself in the package users' shoes. As a maintainer, I might be missing things that are obvious to someone using the package.

Copy link
Owner

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generally looks good to me. Some bigger notes are:

  1. We should adopt this in the example/migrations project (if necessary, copy the existing schema dumps into the directory where this tool would expect them). Then let's add a section at the top of the readme showing how to use the new all-in-one command. We can keep the older commands as a reference for users who need manual control.
  2. Since we expect that most users will want to run this command instead of the previous multiple invocations, let's highlight it more prominently. I think it deserves to be at the top of the migrations tooling page, mentioning that it does everything the other commands are doing in a single step, and that the other commands are then mostly intended for users needing more customization / integration into other tools.
  3. Instead of pointing to --help on the documentation website, I think the website should give an introduction into the command or at least point to the migrations example. The colorful usage output looks great, but users will probably expect this information on the site as well.

drift_dev/lib/src/cli/commands/make_migrations.dart Outdated Show resolved Hide resolved
drift_dev/lib/src/cli/commands/make_migrations.dart Outdated Show resolved Hide resolved
drift_dev/lib/src/cli/commands/make_migrations.dart Outdated Show resolved Hide resolved
drift_dev/lib/src/cli/commands/make_migrations.dart Outdated Show resolved Hide resolved
drift_dev/lib/src/cli/commands/make_migrations.dart Outdated Show resolved Hide resolved
drift_dev/test/cli/make_migrations_test.dart Show resolved Hide resolved
drift_dev/lib/api/migrations.dart Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to commit October 6, 2024 12:29 Inactive
@github-actions github-actions bot temporarily deployed to pull request October 6, 2024 12:29 Inactive
@dickermoshe
Copy link
Collaborator Author

Agree, moved around some around of the docs.

@github-actions github-actions bot temporarily deployed to commit October 6, 2024 12:48 Inactive
@github-actions github-actions bot temporarily deployed to pull request October 6, 2024 12:48 Inactive
@github-actions github-actions bot temporarily deployed to pull request October 6, 2024 13:22 Inactive
@github-actions github-actions bot temporarily deployed to commit October 6, 2024 13:22 Inactive
@dickermoshe dickermoshe marked this pull request as draft October 6, 2024 15:10
@dickermoshe dickermoshe marked this pull request as ready for review October 6, 2024 15:13
@github-actions github-actions bot temporarily deployed to commit October 10, 2024 20:20 Inactive
@github-actions github-actions bot temporarily deployed to pull request October 10, 2024 20:20 Inactive
Copy link
Owner

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great work! LGTM.

I'll just try to get the CI fixed :D

@github-actions github-actions bot temporarily deployed to commit October 10, 2024 20:29 Inactive
@github-actions github-actions bot temporarily deployed to pull request October 10, 2024 20:29 Inactive
@simolus3 simolus3 merged commit 4cadb06 into develop Oct 10, 2024
33 checks passed
@simolus3 simolus3 deleted the drift_migrator_tool branch October 10, 2024 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generated Tests
2 participants